package edu.jit.flowers.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import edu.jit.flowers.bean.Feedbacks;
import edu.jit.flowers.bean.Orders;
import edu.jit.flowers.bean.Users;
import edu.jit.flowers.utils.JDBCUtil;

public class FeedbacksDAO {
	//管理员查看反馈信息--查询所有反馈
	public List<Feedbacks> selectAll(){
		List<Feedbacks> feedbacks = new ArrayList<>();
		String sql="select fb_id as fbid,fb_name as fbname,fb_tel as fbtel"
				+ "fb_email as fbemail from feedbacks";
		QueryRunner runner=new QueryRunner(JDBCUtil.getDataSource());
		try {
			feedbacks=runner.query(sql, new BeanListHandler<>(Feedbacks.class));
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
       return feedbacks;
    }
	//用户反馈信息---增加操作
	public int addFeedbacks(Feedbacks fb) {
	   	 int rows=0;
	   	 String sql="insert into feedbacks values(0,?,?,?)";
	   	 
	   	 QueryRunner runner=new QueryRunner(JDBCUtil.getDataSource());
	   	 try {
				rows=runner.update(sql, fb.getFbName(),fb.getFbTel(),fb.getFbEmail());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	   	 return rows;
	   	 
	    }
	//管理员删除反馈信息---删除
	public int deleteFeedbacksById(Feedbacks fb) {
	   	 int rows=0;
	   	 String sql="delete from feedbacks where fb_id = ?";
	   	 QueryRunner runner=new QueryRunner(JDBCUtil.getDataSource());
	   	 try {
				rows=runner.update(sql, fb.getFbId());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
	   	 return rows;
	    }
	//修改反馈信息  
	public int updateFeedbacksById(Feedbacks fb) {
		int rows=0;
		String sql="update feedbacks set fb_name=?,fb_tel=?,fb_email=? where fb_id=?";
		QueryRunner runner=new QueryRunner(JDBCUtil.getDataSource());
		try {
			rows=runner.update(sql, fb.getFbId());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return rows;
	}

}
